package mesweb.mesweb.controller.wms;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farvision.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import mesweb.mesweb.entity.wms.wmsWwarehouseStorage;
import mesweb.mesweb.service.wms.IwmsWwarehouseStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 设备表
 * @Author: jeecg-boot
 * @Date:   2021-12-07
 * @Version: V1.0
 */
@Slf4j
@Api(tags="设备表")
@RestController
@RequestMapping("/mesweb/wmsWwarehouseStorage")
public class wmsWwarehouseStorageController {
	@Autowired
	private IwmsWwarehouseStorageService wmsWwarehouseStorageService;


    @GetMapping("/GetAll")
    @ApiOperation("获取全部数据列表")
    public CommonResult<?> GetAll(@ApiParam("名称") @RequestParam( value = "name",required = false) String name) {
        List<wmsWwarehouseStorage> data = new ArrayList<>();
        if (StringUtils.isBlank(name) || name.equals("全部")) {
            data = wmsWwarehouseStorageService.list();
        } else {
            QueryWrapper<wmsWwarehouseStorage> queryWrapper = new QueryWrapper<>();
            data = wmsWwarehouseStorageService.list(queryWrapper);
        }
        return CommonResult.success(data);
    }
	/**
	 * 分页列表查询
	 *
	 * @param wmsWwarehouseStorage
	 * @param page
	 * @param size
	 * @param req
	 * @return
	 */
	@ApiOperation(value="设备表-分页列表查询", notes="设备表-分页列表查询")
	@GetMapping(value = "/list")
	public CommonResult<?> queryPageList(wmsWwarehouseStorage wmsWwarehouseStorage,
								   @RequestParam(name="page", defaultValue="1") Integer page,
								   @RequestParam(name="size", defaultValue="10") Integer size,
								   HttpServletRequest req) {
		QueryWrapper<wmsWwarehouseStorage> queryWrapper = new QueryWrapper<>();
		Page<wmsWwarehouseStorage> pagewmsWwarehouseStorage = new Page<wmsWwarehouseStorage>(page, size);
		IPage<wmsWwarehouseStorage> pageList = wmsWwarehouseStorageService.page(pagewmsWwarehouseStorage, queryWrapper);
		return CommonResult.success(pageList);
	}
	/**
	 * 编辑
	 *
	 * @param wmsWwarehouseStorage
	 * @return
	 */
	@ApiOperation(value="设备表-编辑", notes="设备表-编辑")
	@PostMapping(value = "/save")
	public CommonResult<?> edit(@RequestBody wmsWwarehouseStorage wmsWwarehouseStorage) {
       boolean result = false;
        if(wmsWwarehouseStorage.getId() == 0L) {
             result = wmsWwarehouseStorageService.save(wmsWwarehouseStorage);
        }
        else
        {
            result = wmsWwarehouseStorageService.updateById(wmsWwarehouseStorage);
        }
        return CommonResult.success(result);
	}

	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="设备表-通过id删除", notes="设备表-通过id删除")
	@DeleteMapping(value = "/delete")
	public CommonResult<?> delete(@RequestParam(name="id",required=true) String id) {
		wmsWwarehouseStorageService.removeById(id);
		return CommonResult.success("删除成功!");
	}

	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="设备表-批量删除", notes="设备表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public CommonResult<?> deleteBatch(@ApiParam("wmsWwarehouseStorageIDs") @RequestBody List<Long> ids) {
		this.wmsWwarehouseStorageService.removeByIds(ids);
		return CommonResult.success("批量删除成功！");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="设备表-通过id查询", notes="设备表-通过id查询")
	@GetMapping(value = "/queryById")
	public CommonResult<?> queryById(@RequestParam(name="id",required=true) String id) {
		wmsWwarehouseStorage wmsWwarehouseStorage = wmsWwarehouseStorageService.getById(id);
		return CommonResult.success(wmsWwarehouseStorage);
	}
}
